﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Praxis.Entities;

namespace Praxis.Repository
{
    public class ObraDAO:MasterRepository, IObraDAO
    {
        public List<OBRA> GetAllObras()
        {
            var query = from c in Context.OBRAs
                        select c;
            return query.ToList();
        }

        public List<OBRA> GetFromObraByDescripcion(string descripcion)
        {
            if (descripcion != "")
            {
                var query = from c in Context.OBRAs
                            where c.Nombre.ToUpper().Contains(descripcion.ToUpper())
                            select c;
                return query.ToList();
            }
            else
            {
                var query1 = from c in Context.OBRAs
                             select c;
                return query1.ToList();
            }
        }

        public OBRA GetFromObraById(int id)
        {
            return Context.OBRAs.Find(id);
        }

        public void AddObra(OBRA obra)
        {
            Context.OBRAs.Add(obra);
            Context.SaveChanges();
        }

        public void UpdateObra(OBRA obra)
        {
            Context.Entry(obra).State = System.Data.EntityState.Modified;
            Context.SaveChanges();
        }


        public List<OBRA> GetFromObrasByEmpresa(string empresa)
        {
            if (empresa != "")
            {
                var query = from c in Context.OBRAs
                            where c.Empresa.ToUpper().Contains(empresa.ToUpper())
                            select c;
                return query.ToList();
            }
            else
            {
                var query1 = from c in Context.OBRAs
                             select c;
                return query1.ToList();
            }
        }
    }
}
